var security = [['1', '普通'], ['2', '秘密'], ['3', '机密'], ['5', '绝密']];

var storeSecurity = new Ext.data.SimpleStore({
    fields: ['value', 'text'],
    data: security
});

var urgence = [['0', '普通'], ['5', '紧急'], ['10', '特急']];

var storeUrgence = new Ext.data.SimpleStore({
    fields: ['value', 'text'],
    data: urgence
});

var language = [['1', '汉语'], ['2', '藏语']];

var storeLanguage = new Ext.data.SimpleStore({
    fields: ['value', 'text'],
    data: language
});

var storeCategory = new Ext.data.JsonStore({
    url: 'contributer_view.action',
    root: 'manuscriptCategoryList',
    fields: ['manuscriptCategoryId', 'manuscriptCategoryName']
});

storeCategory.load();

var form_contributer = new Ext.form.FormPanel({
    title: '递交原稿',
    id: 'contributer_from',
    labelAlign: 'right',
    labelWidth: 94,
    frame: true,
    fileUpload: true,
    region: 'center',
    items: [{
        fieldLabel: '稿件上传',
        xtype: 'fileuploadfield',
        emptyText: '请选择文件',
        allowBlank: false,
        name: 'fileuploadfield',
        validator:function(value){
    	  var type=['rar','doc','xls','pdf','ppt','txt','zip','docx'];
    		if(value==''){
    			return '请上传稿件';
    		}else{
    			var fileType=value.substring(value.lastIndexOf(".")+1).toLowerCase();
    			for(var i=0;i<type.length;i++){
    				if(type[i]==fileType){
    					return true;
    				}
    			}
    			return '请上传如下格式的文件:[rar,doc,xls,pdf,ppt,txt,zip,docx]';
    		}
    	},
        width: '410',
        itemCls: 'clear'
    }, {
        layout: 'fit',
        items: [{
            title: '详细设置',
            autoHeight: true,
            xtype: 'fieldset',
            layout: 'form',
            xtype: 'fieldset',
            items: [{
                xtype: 'textfield',
                name: 'manuscript.title',
                allowBlank: false,
                fieldLabel: '稿件标题',
                maxLength: 50,
                itemCls: 'form_long clear'
            }, {
                xtype: 'combo',
                store: storeLanguage,
                hiddenName: 'manuscript.language',
                allowBlank: false,
                editable: false,
                fieldLabel: '原稿文种',
                emptyText: '请选择',
                mode: 'local',
                triggerAction: 'all',
                valueField: 'value',
                displayField: 'text',
                itemCls: 'form_text'
            }, {
                xtype: 'combo',
                store: storeLanguage,
                hiddenName: 'manuscript.targetLanguage',
                allowBlank: false,
                editable: false,
                fieldLabel: '目标语言',
                emptyText: '请选择',
                mode: 'local',
                triggerAction: 'all',
                valueField: 'value',
                displayField: 'text',
                itemCls: 'form_text'
            }, {
                xtype: 'combo',
                store: storeUrgence,
                hiddenName: 'manuscript.urgence',
                allowBlank: false,
                editable: false,
                fieldLabel: '紧急程度',
                emptyText: '请选择',
                mode: 'local',
                triggerAction: 'all',
                valueField: 'value',
                displayField: 'text',
                itemCls: 'form_text'
            }, {
                xtype: 'combo',
                store: storeCategory,
                hiddenName: 'manuscript.manuscriptCategoryId',
                allowBlank: false,
                editable: false,
                fieldLabel: '稿件分类',
                emptyText: '请选择',
                mode: 'local',
                triggerAction: 'all',
                valueField: 'manuscriptCategoryId',
                displayField: 'manuscriptCategoryName',
                itemCls: 'form_text',
                listeners: {
                    "focus": function(){
                        if (storeCategory.getTotalCount() == 0) {
                            Ext.Msg.show({
                                title: '操作提示',
                                msg: '请管理员添加稿件分类!',
                                buttons: Ext.Msg.OK,
                                icon: Ext.Msg.INFO,
                                width: 200
                            });
                        }
                    }
                }
            }, {
                xtype: 'combo',
                store: storeImportance,
                hiddenName: 'manuscript.importance',
                allowBlank: false,
                editable: false,
                fieldLabel: '重要性',
                emptyText: '请选择',
                mode: 'local',
                triggerAction: 'all',
                valueField: 'value',
                displayField: 'text',
                itemCls: 'form_text'
            }, {
                xtype: 'datefield',
                name: 'plannedConsummationTime',
                editable: false,
                minValue: new Date().format('Y-m-d'),
                emptyText: '请选择',
                allowBlank: false,
                fieldLabel: '计划完成时间',
                format: 'Y-m-d',
                itemCls: 'form_text'
            }, {
                xtype: 'combo',
                store: storeSecurity,
                hiddenName: 'manuscript.securityClassification',
                allowBlank: false,
                editable: false,
                fieldLabel: '密级',
                emptyText: '请选择',
                mode: 'local',
                triggerAction: 'all',
                valueField: 'value',
                displayField: 'text',
                itemCls: 'form_text'
            }, {
                xtype: 'numberfield',
                name: 'manuscript.wordNum',
                allowBlank: false,
                fieldLabel: '预估字数',
                allowNegative: false,
                allowDecimals: false,
                regex: /^[1-9][0-9]{0,8}$/,
                regexText: '请输入长度小于等于9且最小值为1的合法正整数',
                itemCls: 'form_text'
            }]
        }]
    }, {
        layout: 'fit',
        items: [{
            title: '可选设置',
            autoHeight: true,
            xtype: 'fieldset',
            layout: 'form',
            xtype: 'fieldset',
            items: [{
                xtype: 'textarea',
                name: 'manuscript.remark',
                allowBlank: true,
                fieldLabel: '备注',
                itemCls: 'clear',
                maxLength: 200,
                width: '410',
                height: '120'
            }]
        }]
    }],
    buttons: [{
        text: '提交',
        type: 'submit',
        handler: function(){
    	if(form_contributer.form.isValid()){
    		Ext.Msg.confirm('提交确认', '你确定要提交稿件?', function(btn){
    			if (btn == 'yes') {
    				form_contributer.form.doAction('submit', {
    					url: 'contributer_add.action',
    					method: 'post',
    					waitTitle:'正在处理' ,
    					waitMsg: '请稍等......',
    					success: function(form, action){
    					if (action.result.success) {
							if(action.result.uploadSuccess==undefined){
								Ext.Msg.show({
									title: '操作提示',
									msg: '文件大于最大允许值50M!',
									buttons: Ext.Msg.OK,
									icon: Ext.Msg.ERROR,
									width: 200
								});
							}else if(action.result.uploadSuccess=="true"){
								Ext.Msg.show({
									title: '操作提示',
									msg: '递交成功!',
									buttons: Ext.Msg.OK,
									icon: Ext.Msg.INFO,
									width: 200,
									fn:function(){
										form_contributer.form.reset();
									}
								});
							}
					}
    					else {
    						Ext.Msg.show({
    							title: '错误提示',
    							msg: action.result.errorMessage,
    							buttons: Ext.Msg.OK,
    							icon: Ext.Msg.ERROR,
    							width: 200
    						});
    					}
    				},
    				failure: function(form, action){
    					if (action.result == null) {
    						Ext.Msg.show({
    							title: '错误提示',
    							msg: '数据不符合要求',
    							buttons: Ext.Msg.OK,
    							icon: Ext.Msg.ERROR,
    							width: 200
    						});
    					}
    					else {
    						if (!action.result.success) {
    							if(action.result.uploadSuccess==undefined){
    								Ext.Msg.show({
    									title: '错误提示',
    									msg: "文件大于最大允许值50M!",
    									buttons: Ext.Msg.OK,
    									icon: Ext.Msg.ERROR,
    									width: 200
    								});
    							}else{
    								Ext.Msg.show({
    									title: '错误提示',
    									msg: "未知错误！",
    									buttons: Ext.Msg.OK,
    									icon: Ext.Msg.ERROR,
    									width: 200
    								});
    							}
    						}
    					}
    				}
    				});
    			}
    		});
    	}
            
        }
    }, {
        text: '重置',
        handler: function(){
            form_contributer.form.reset();
        }
    }]
});
var a_contributer = {
    id: 'contributer-add',
    border: false,
    layout: 'border',
    items: [form_contributer]
};
Ext.getCmp('content-panel').add(a_contributer);
Ext.getCmp('content-panel').layout.setActiveItem('contributer-add');
